import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

/**
 * 
 */

/**
 * @author dan
 *
 */
public class Forum {

	/**
	 * 
	 */
	private String forumId;
	private ArrayList<Topic> topics = new ArrayList<Topic>();
	
	private HashMap<String,ParticipationLog> plList = new HashMap<String, ParticipationLog>(); 
	
	public HashMap<String, ParticipationLog> getPlList() {
		return plList;
	}

	public void setPlList(HashMap<String, ParticipationLog> plList) {
		this.plList = plList;
	}

	public String getForumId() {
		return forumId;
	}

	public void setForumId(String forumId) {
		this.forumId = forumId;
	}

	public ArrayList<Topic> getTopics() {
		return topics;
	}

	public void setTopics(ArrayList<Topic> topics) {
		this.topics = topics;
	}


	public Forum() {
		// TODO Auto-generated constructor stub
	}

	public Forum(String name) {
		// TODO Auto-generated constructor stub
		forumId = name;
	}

	public String exportCSV(){
		String result = "";
		result +="User,No_Sent_Messages,No_Receive_Messages,No_Sent_Chars,No_Receive_Chars, No_Topics, No_Users_Receive, No_Users_Sent\n";
		for (Iterator it = this.plList.values().iterator(); it.hasNext();) {
			ParticipationLog log = (ParticipationLog) it.next();
			result	+=	log.exportCSV();
		}
		return result;
	}
	
	public void add(Utterance u){
		
		//check if it is existing user
		if( plList.containsKey(u.getUserId()) ){
			ParticipationLog log = plList.get(u.getUserId());
			log.addLog(u, true);
		}
		else{
			plList.put(u.getUserId(), new ParticipationLog(u,true));
		}
		
		//check if the ref user exist
		if( plList.containsKey(u.getRefUserId()) ){
			ParticipationLog log = plList.get(u.getRefUserId());
			log.addLog(u, false);
		}
		else{
			plList.put(u.getRefUserId(), new ParticipationLog(u,false));
		}
		
	}
	
}
